<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <title>修改员工</title>
    <link href="/res/css/respective/order/back-order.css" rel="stylesheet">
    <link href="/res/third/dropdown/dropdownlist.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .back-main a {
            text-decoration: none !important;
        }

        .blueBtn {
            display: inline-block;
            height: 32px;
            line-height: 32px;
            margin: 3px 0;
            text-align: center;
            color: #fff;
            background: #00b1db;
            border-radius: 3px;
            cursor: pointer;
            padding: 0 10px;
        }

        .grayBtn {
            display: inline-block;
            height: 32px;
            line-height: 32px;
            margin: 3px 0;
            text-align: center;
            color: #fff;
            background: gray;
            border-radius: 3px;
            cursor: pointer;
            padding: 0 10px;
        }
        
       .mainline{display: inline-block;width: 100%;}
	   .labeldiv{display: inline-block;float: left;line-height: 34px;width: 192px;text-align: right;margin-right: 30px;height: 34px;font-size: 14px;color:#6e7b8e;}
	   .inputdiv{display:inline-block;float: left;}
	   .centerSpace{display: inline-block;width: 100%;height: 15px;}
	   .save{display: inline-block;background-color: #00B1DB;width: 88px;height: 32px;border-radius:2px;color: #fff;font-weight: bold;text-align: center;line-height: 32px;float: left;cursor: pointer;border: 1px solid #00B1DB;;}
	   .save:hover{
	   	background-color: #00ceff;
	   	border-color: #00ceff;
	   }
	   .cancle:hover{
	   	background-color: #00ceff;
	   	color: white;
	   	border-color: #00ceff;
	   }
	   .saveandadd{display: inline-block;background-color: #F7A226;width: 150px;height: 32px;border-radius:2px;color: #fff;font-weight: bold;text-align: center;line-height: 32px;float: left;cursor: pointer;}
	   .cancle{display: inline-block;width: 88px;height: 32px;border-radius:2px;color: #37C0E1;font-weight: bold;text-align: center;line-height: 31px;border: 1px solid #37C0E1;float: left;cursor: pointer;}
	   .warp-supplier .save{
	   	background-color: rgb(254, 169, 16);
		border:1px solid rgb(254, 169, 16);
		color: white;
	   }
	   .warp-supplier .save:hover{
	   	background-color: rgb(255, 192, 1);
		border:1px solid rgb(255, 192, 1);
		color: white;
	   }
	    .warp-supplier .cancle{ 
		border:1px solid rgb(254, 169, 16);
		color: rgb(254, 169, 16);
	   }
	   .warp-supplier .cancle:hover{
	   	background-color: rgb(255, 192, 1);
		border:1px solid rgb(255, 192, 1);
		color: white;
	   }
	   .emptext{border: 1px solid #ccc;width: 270px;border-radius:2px;}
	   .star{color:#F9A744;}
	   .loginmsg{display: inline-block;float: left;line-height: 34px;text-align: left;margin-left: 20px;height: 34px;font-size: 14px;color:#6e7b8e;}
	   .dropdown-input{width: 224px!important;}
	   .alertpic{display: inline-block;width: 20px;height: 20px;}
	   .texttrue{width: 21px;height: 21px;display: inline-block;float: left;background-image: url("/res/images/oparaStatus/dapp.png");background-position: -44px -42px;margin-top: 6px;margin-left: 10px;}
	   .textfalse{width: 21px;height: 21px;display: inline-block;float: left;background-image: url("/res/images/oparaStatus/dapp.png");background-position: -11px -42px;margin-top: 6px;margin-left: 10px;}
    </style>
</head>
<body>
<div class="warp">
[#include "/front/common/front_headAzt.html"]
    <div class="backcontent">
    [#include "/front/common/front_leftAzt.html"]
        <div class="back-main">
            <div class="inner">
                <div class="title" id="bedoreEmp">员工管理</div>
                <form id="addUserForm" action="addUser">
							<div class="table-responsive">
								<div class="mainline">
								 	 <span class="labeldiv"><b class="star">*</b>登录账号：</span>
								 	 <div class="inputdiv">
								 	 		<input type="text" name="login" class="emptext" value="[#if user.mobile??]${user.mobile!}[#else]${user.email!}[/#if]" placeholder="请输入登录手机号或者邮箱" >
								 	 </div>
								 	 <span class="alertpic"></span><div class="loginmsg"></div>
								</div>
								 <div class="centerSpace"></div>
								 <div class="mainline">
								 	 <span class="labeldiv"><b class="star">*</b>所属角色：</span>
								 	 <div class="inputdiv">
								 	 		<input type="hidden">
								 	 		<select id="demo2" name="roleId">
								 	 			[#list roles as role]
								 	 				<option  value="${role.id!}" [#if role.id==uRole.id]selected="selected"[/#if]>${role.name!}</option>
								 	 			[/#list]
								 	 		</select>
								 	 </div>
								 	 <span class="labeldiv" style="width: 85px;cursor: pointer;" onclick="window.open('/orgstruct/addrole')"><img src="/res/images/add/addRole_03.png">  添加角色</span>
								 </div>
								 <div class="centerSpace"></div>
								 <div class="mainline">
								 	 <span class="labeldiv">员工姓名：</span>
								 	 <div class="inputdiv">
								 	 		<input type="text" name="realName" class="emptext" placeholder="请输入员工姓名" value="${user.realName!}">
								 	 </div>
								 	 <span class="alertpic"></span><div class="loginmsg"></div>
								 </div>
								 <div class="centerSpace"></div>
								 <div class="mainline">
								 	 <span class="labeldiv">联系电话：</span>
								 	 <div class="inputdiv">
								 	 		<input type="text" name="contactTel" class="emptext" placeholder="请输入联系电话" value="${user.contactTel!}">
								 	 </div>
								 	 <span class="alertpic"></span><div class="loginmsg"></div>
								 </div>
								 <div class="centerSpace"></div>
								 <div class="mainline">
								  	 <div class="labeldiv"></div>
								 	 <div class="inputdiv">
								 	 	   <div class="save" style="margin-right: 10px;" id="doSaveEmp">保存</div>
								 	 	   <div class="cancle" onclick="history.go(-1)">返回</div>
								 	 </div>
								 </div>
								 <div class="centerSpace"></div>
							</div>
				    </form>
            </div>
        </div>
    </div>

[#include "/front/common/front_footerAzt.html"]
</div>

<script type="text/javascript" src="/res/js/common/jquery.1.9.1.min.js"></script>
<script type="text/javascript" src="/res/js/structure/struture.js"></script>
<script type="text/javascript" src="/res/js/common/common.js"></script>
<script type="text/javascript" src="/res/third/laydate/laydate.js"></script>
<script type="text/javascript" src="/res/third/layer/layer.js"></script>
<script type="text/javascript" src="/res/js/common/tppl.js"></script>
<script type="text/javascript" src="/res/third/nice-validator/jquery.validator.min.js?local=zh-CN"></script>
<script src="/res/third/dropdown/js/dropdownlist.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	 var isSubmit=true;
	 var user={};
	 user.id='${user.id}'
	 user.originRoleid='${uRole.id}';
	 user.roleId='${uRole.id}';
	    // 通过原生select控件创建自定义下拉框
	    var ddl_picture = DropDownList.create({
	        select:$('#demo2'),
	        attrs:{
	            column :100,
	            width :200,
				
	        }
	    });
		ddl_picture.change(function(){
			user.roleId=ddl_picture.val();
			//alert(ddl_picture.val());
		}); 
	  var ischangeAccountInEdit=false;
	  var account='[#if user.mobile??]${user.mobile!}[#else]${user.email!}[/#if]';
	  var mob='[#if user.mobile??]${user.mobile!}[/#if]'
      var ema='[#if user.email??]${user.email!}[/#if]'
		//登录框
		 function validateLogin(loginNode,flag){
			 isSubmit=true;
			 var login=loginNode.val().trim();
			 if(login==mob||login==ema){
				 ischangeAccountInEdit=false;
			 }else{
				 ischangeAccountInEdit=true;
			 }
			 var node=loginNode;
			 node.parents(".mainline").find(".loginmsg").children().remove();
			 node.parents(".mainline").find(".alertpic").removeClass("textfalse");
			 node.parents(".mainline").find(".alertpic").removeClass("texttrue");
			 if(login==''){
				 node.parents(".mainline").find(".alertpic").addClass("textfalse");
				 node.parents(".mainline").find(".loginmsg").append("<span style='color:red;'>账号不能为空！</span>");
				 isSubmit=false
				 return isSubmit;
			 }else{
				 var mobile=/^1[3-9]\d{9}$/;
				 var email=/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i;
				 if(!mobile.test(login)){
					 if(!email.test(login)){
						 node.parents(".mainline").find(".alertpic").addClass("textfalse")
						 node.parents(".mainline").find(".loginmsg").append("<span style='color:red;'>账号格式不正确！</span>");
						 isSubmit=false;
						 return isSubmit;
					 }else{
						 user.mobile=null;
						 user.email=login;
					 }
				 }else{
					 user.email=null;
					 user.mobile=login;
				 }
			 }
			 if(ischangeAccountInEdit!=false){
				 var layerIndex;
				 $.ajax({
			         url : 'validateUser',
			         type : 'post',
			         async:flag,
			         dataType : 'json',
			         data:{login:login,ifedit:1},
					 beforeSend : function () {
							layerIndex = layer.load(1, {
								  shade: [0.1,'#fff'] //0.1透明度的白色背景
								});
			         },
			         success : function(data) {
			             if(data.success==false){
			            	 node.parents(".mainline").find(".alertpic").addClass("textfalse")
			            	 node.parents(".mainline").find(".loginmsg").append("<span style='color:red;'>"+data.msg+"</span>");
			            	 $("[name='realName']").val("");
		            		 $("[name='contactTel']").val("");
			             }else{
			            	 if(flag==false)return;
			            	 
			            	 if(data.attributes.type=="1"){
			            		 node.parents(".mainline").find(".alertpic").addClass("texttrue");
			            		 node.parents(".mainline").find(".loginmsg").append("<span>"+data.msg+"</span>");
			            		 $("[name='realName']").val("");
			            		 $("[name='contactTel']").val("");
			            	 }else{
			            		 node.parents(".mainline").find(".alertpic").addClass("texttrue");
			            		 node.parents(".mainline").find(".loginmsg").append("<span>"+"用户名："+"<b style='color:#F7A226;'>"+data.attributes.login+"</b>"+"，可以修改</span>");
			            		 $("[name='realName']").val(data.attributes.realName);
			            		 $("[name='contactTel']").val(data.attributes.contactTel);
			            	 }
			            	 //user.id=data.attributes.uid;
			             }
			         },
					 complete : function() {
						layer.close(layerIndex);
					 }
			     })
			 }
		 }
		
	 //名字
	 function validateRealName(){
		 var realName=$("[name='realName']");
		 realName.parents(".mainline").find(".loginmsg").children().remove();
		 realName.parents(".mainline").find(".alertpic").removeClass("textfalse");
		 if(!realName.val().trim()){
			 /* 
			 realName.parents(".mainline").find(".loginmsg").append("<span style='color:red;'>该字段不能为空！</span>");
			 isSubmit=false;
			 */
			 user.realName=null;
		 }else{
			 var res1=/^[\u4e00-\u9fa5]{2,8}$/;
			 var res2=/^[a-zA-Z]{2,16}$/;
			 if(!res1.test(realName.val().trim())&&!res2.test(realName.val().trim())){
				 realName.parents(".mainline").find(".alertpic").addClass("textfalse");
				 realName.parents(".mainline").find(".loginmsg").append("<span style='color:red;'>姓名格式不正确,支持2-8位中文字符或者2-16英文字符</span>");
				 isSubmit=false
			 }else{
				 user.realName=realName.val().trim();
			 }
		 }
	 }
	 //电话
	 function validateContactTel(){
		 var contactTel=$("[name='contactTel']");
		 contactTel.parents(".mainline").find(".loginmsg").children().remove();
		 contactTel.parents(".mainline").find(".alertpic").removeClass("textfalse");
		 if(!contactTel.val().trim()){
			 /* 
			 contactTel.parents(".mainline").find(".loginmsg").append("<span style='color:red;'>该字段不能为空！</span>");
			 isSubmit=false;
			 */
			 user.contactTel='';
		 }else{
			 user.contactTel=contactTel.val().trim();
			 /*
			 var res=/^1[3-9]\d{9}$/;
			 if(!res.test(contactTel.val().trim())){
				 contactTel.parents(".mainline").find(".alertpic").addClass("textfalse");
				 contactTel.parents(".mainline").find(".loginmsg").append("<span style='color:red;'>请填写有效的电话号码！</span>");
				 isSubmit=false
			 }else{
				 user.contactTel=contactTel.val().trim();
			 }
			 */
		 }
	 }
 	 
	 $("[name='login']").focusout(function(){
		 validateLogin($(this),true);
	 })
	 $("[name='realName']").focusout(function(){
		 validateRealName();
	 })
	 $("[name='contactTel']").focusout(function(){
		 validateContactTel();
	 });
	 function subvalidate(flag){
		 validateLogin($("[name='login']"),flag);
		 validateRealName();
		 validateContactTel();
	 }
	 $("#doSaveEmp").click(function(){
		 subvalidate(false);
		 if(isSubmit){
			 if(ischangeAccountInEdit){
				 layer.confirm('确认修改账号吗？现有的账号权限将全部转移到新的账号上，并自动解绑当前公司', {icon: 3, title:'提示'}, function(index){
					 dosubmitEdit();
					 layer.close(index);
				});
			 }else{
				 dosubmitEdit();
			 }
			 
		 }
	 });
	 
	 function dosubmitEdit(){
		 var layerIndex;
		 $.ajax({
	         url : 'doEditUser',
	         type : 'post',
	         dataType : 'json',
	         contentType : "application/json; charset=utf-8",
	         data:JSON.stringify(user),
			 beforeSend : function () {
				 layerIndex = layer.load(1, {
					  shade: [0.1,'#fff'] //0.1透明度的白色背景
					});
	         },
	         success : function(data) {
	        	 if(data.success){
	            	 layer.alert("修改成功",function(){
	            		 location.href='/employee/employee_list';
	            	 });
	             }else{
	            	 layer.alert(data.msg);
	             }
	         },
			 complete : function() {
				layer.close(layerIndex);
			 }
	     })
	 }
});
</script>
</body>
</html>